﻿Shader "Unlit/BrushShader"
{
	Properties
	{
		_MainTex("Texture", 2D) = "white" {}

	}
		SubShader
	{
		Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" }
		ZWrite Off
		Cull Off
		Blend SrcAlpha OneMinusSrcAlpha
		LOD 100

		Pass
	{
		CGPROGRAM
#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"

		struct appdata
	{
		float4 vertex : POSITION;
		float2 uv : TEXCOORD0;
	};

	struct v2f
	{
		float2 uv : TEXCOORD0;
			float4 vertex : SV_POSITION;
		float4 proj : TEXCOORD2;
	};

	sampler2D _MainTex;
	float4 _MainTex_ST;
	sampler2D_float _CameraDepthTexture;
	float4 _Color;
	v2f vert(appdata v)
	{
		v2f o;
		o.vertex = UnityObjectToClipPos(v.vertex);
		o.proj = ComputeScreenPos(o.vertex);
		COMPUTE_EYEDEPTH(o.proj.z);
		//Use this for linear one                        
		//o.proj.z = COMPUTE_DEPTH_01;
		o.uv = TRANSFORM_TEX(v.uv, _MainTex);

		return o;
	}

	fixed4 frag(v2f i) : SV_Target
	{
		// sample the texture
		fixed4 col = tex2D(_MainTex, i.uv);
	float depth = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, i.proj.xy / i.proj.w));

	float a = saturate(depth - i.proj.z);
	a = smoothstep(0., 0.2, a);
	a = 1. - a;
	a = pow(a, 10.);
	col.a *= a;
	return col* _Color;
	}
		ENDCG
	}
	}
}
